package com.example.administrator.androidhomework1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
   EditText mEtHeight;
   RadioGroup mRgSex;
   Button mBtnCompute;
   TextView mTvResult;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mEtHeight = findViewById(R.id.et_height);

        mRgSex = findViewById(R.id.rg_sex);

        mBtnCompute = findViewById(R.id.btn_compute);
        mTvResult = findViewById(R.id.tv_result);

        mBtnCompute.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String sHeight = mEtHeight.getText().toString();
                int height = Integer.parseInt(sHeight);

                int id = mRgSex.getCheckedRadioButtonId();

                if (id == R.id.rd_male){
                    int standardWeight =(int)((height - 100)*0.9);

                    //mTvResult.setText("标准体重是："+standardWeight +"");
                    Toast.makeText(MainActivity.this, "标准体重是：", Toast.LENGTH_SHORT).show();


                }else if (id == R.id.rd_famale) {
                    int standardWeght = (int)((height-100)*0.9-2.5);
                    mTvResult.setText("标准体重是："+standardWeght+"KG");
                }
            }
        });
    }
}
